	SUBROUTINE YXHG(N,X,Y,A,B,Q,S,P,UMAX,UMIN,U)
	REAL(4),DIMENSION(N)::X,Y
	XV=0         !x的均值
	YV=0         !y的均值
	DO I=1,N
		XV=XV+X(I)
		YV=YV+Y(I)
	END DO
	XV=XV/N
	YV=YV/N
	DXX=0.0
	DXY=0.0
	DO I=1,N
		Q=X(I)-XV
		DXX=DXX+Q*Q
		DXY=DXY+Q*(Y(I)-YV)
	END DO
	A=DXY/DXX
	B=YV-A*XV
	Q=0
	U=0
	P=0
	UMAX=-1.0E10
	UMIN=1.0E20
	DO I=1,N
		S=A*X(I)+B
		Q=Q+(Y(I)-S)**2
		P=P+(S-YV)**2
		DX=ABS(Y(I)-S)
		IF(DX.GT.UMAX)THEN
			UMAX=DX
		ENDIF
		IF(DX.LT.UMIN)THEN
			UMIN=DX
		ENDIF
		U=U+DX/N
	END DO
	S=SQRT(Q/N)
	END
	PROGRAM main1
	INTEGER,PARAMETER::N=22
	REAL(4),DIMENSION(N)::X,Y
      DATA X/16.80,15.60,15.60,14.00,18.95,18.50,16.50,15.35,17.50,17.00
     &,17.30,14.30,13.75,14.00,12.00,16.30,14.40,12.90,13.00,15.00,13.70
     &,14.00/
	DATA Y/16.20,15.80,16.20,18.00,17.70,18.00,16.00,19.00,18.40,15.35
     &,17.00,14.00,14.65,13.30,14.35,15.00,14.35,12.50,14.00,14.50,13.25
     &,14.10/
	CALL YXHG(N,X,Y,A,B,Q,S,P,UMAX,UMIN,U)
	OPEN(9,FILE='RESULT.DAT')
	WRITE(9,10)A,B
 10	FORMAT(1X,'A=',E13.6,2X,'B=',E13.6)
	WRITE(9,15)Q,S,P
 15	FORMAT(1X,'Q=',E13.6,2X,'S=',E13.6,2x,'P=',E13.6)
	WRITE(9,20)UMAX,UMIN,U
 20	FORMAT(1X,'UMAX=',E13.6,2X,'UMIN=',E13.6,2x,'U=',E13.6)
	CLOSE(9)
	END

